package 力扣._8039_使数组成为递增数组的最少右移次数;

import java.util.List;

public class Solution {
    public int minimumRightShifts(List<Integer> nums) {
        //找到小于前面元素的元素，数量<=1则可,否则不可
        int index = -1;
        int total = 0;
        for (int i = 1; i < nums.size(); i++) {

            if (nums.get(i - 1) > nums.get(i)) {
                index = i;
                total++;
            }
        }
        if (total == 0)
            return 0;
        if (total > 1 || nums.get(nums.size() - 1) >= nums.get(0))
            return -1;
        return nums.size() - index;
    }
}
